<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://www.yaodian100.com/jsp/yaodian100" prefix="yaodian100" %>
<style>
.tableAlignLeft td{
	text-align:left;
}
</style>
<script type="text/javascript">
$().ready(function(){
	if(isAllNum($("#soCreater").text())){
		$("#soCreater").append('（客户）');	
	}
});
function isAllNum(str){
	for(var i=0;i<str.length;i++){
		var c = str.charCodeAt(i);
		if(c > 57 || c < 48)
			return false;
	}
	return true;
}
</script>
<c-rt:set var="serviceId" value="${param.serviceId }"/>
<c-rt:if test="${!empty param.orderProdId}">
${pu:listAdd('list', param.orderProdId) }
${pu:reqSet('sops', pu:queryByHql('from ServiceOrderProduct where orderProdId=?', pu:arrayGet('list'), null)) }
<c-rt:set var="serviceId" value="${sops[0].serviceId}"/>
</c-rt:if>


${pu:listAdd('params', serviceId) }
${pu:listAdd('serviceType', '退货单') }
${pu:listAdd('serviceType', '换货单') }
${pu:listAdd('serviceType', '取消单') }
${pu:listAdd('serviceType', '配送异常单') }
${pu:reqSet('stArray', pu:arrayGet('serviceType')) }
${pu:reqSet('so', pu:get('com.yaodian100.ec.order.entity.ServiceOrders', serviceId)) }
${pu:reqSet('sops', pu:queryByHql('from ServiceOrderProduct where serviceId=?', pu:arrayGet('params'), null))}
${pu:reqSet('order', pu:get('com.yaodian100.ec.order.entity.Orders', so.orderId)) }
<%--出货查询 --%>
<c-rt:set var="logisticComp" value="${null }"/>
<c-rt:set var="logisticNum" value="${null }"/>
<c-rt:set var="logisticUrl" value="${null }"/>

<c-rt:forEach items="${sops}" var="sop" varStatus="sopStatus">
	<c-rt:if test="${empty logisticNum}">
	<c-rt:if test="${not empty sop.logisticCompany}">
	${pu:reqSet('lc', pu:get('com.yaodian100.crm.workorder.entity.LogisticProvider', sop.logisticCompany)) }
		<c-rt:set scope="request" var="logisticNum" value="${sop.logisticRefNum } " />
		<c-rt:choose>
			<c-rt:when test="${empty lc}">
				<c-rt:set scope="request" var="logisticComp" value="${lc.name } " />
				<c-rt:set scope="request" var="logisticUrl" value="" />
			</c-rt:when>
			<c-rt:otherwise>
				<c-rt:set scope="request" var="logisticComp" value="${lc.name } " />
				<c-rt:set scope="request" var="logisticUrl" value="${lc.searchUrl } " />				
			</c-rt:otherwise>
		</c-rt:choose>
		</c-rt:if>
	</c-rt:if>
</c-rt:forEach>
<table  class="tb-1 tableAlignLeft">
	<tr>
		<td></td>
		<td></td>
		<td>
		<c-rt:choose>
			<%-- 換貨 --%>
			<c-rt:when test="${so.srcType=='2'}">
				<c-rt:choose>
				<%-- 已完成，且不是換貨轉退貨 --%>
						<c-rt:when test="${so.orderSt=='90' && so.returnSt=='00'}">
						<%-- 無再申請過退換單 --%>
						<c-rt:if test="${empty so.newServiceId}">
							<yaodian100:checkPermission permissions="ROLE_ORD">
								<s:form method="post">
									<s:submit value="申请换货" action="serviceOrder" method="toChangeProduct"></s:submit>
									<s:submit value="申请退货" action="serviceOrder" method="toReturnProduct"></s:submit>
									<s:iterator value="%{#request.sops}" var="serviceOrderProduct">
										<s:hidden name="orderProdId" value="%{#serviceOrderProduct.orderProdId}"></s:hidden>
									</s:iterator>
									<s:hidden name="oldServiceId" value="%{serviceId}" />
								</s:form>
							</yaodian100:checkPermission>
						</c-rt:if>
						</c-rt:when>
				</c-rt:choose>
			</c-rt:when>
		</c-rt:choose>
		</td>
	</tr>
	<tr>
		<td colspan="3">服务单建立者：
		<b id="soCreater">${so.createUser}</b>
		</td>
	</tr>
	<tr>
		<td>类型：
		<b>${stArray[so.srcType-1] }</b>
		</td>
		<td>
		服务单号：${so.serviceId}
		</td>
		<td>
		状态：
		<c-rt:choose>
		<c-rt:when test="${so.srcType=='1'}">
			<c-rt:choose>
				<c-rt:when test="${ so.orderSt=='00' }">
				${so.orderSt }(待审核)
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='10' }">
				申请中
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='20' }">
				退款处理中
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='30' }">
				退货品验收失败
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='50' }">
				退货逾期
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='60' }">
				退货商品退回
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='70' }">
				退货失败
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='80' }">
				退货取消
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='90' }">
				退货完成
				</c-rt:when>
				
			</c-rt:choose>
		
		</c-rt:when>
		<c-rt:when test="${so.srcType=='2'}">
			<c-rt:choose>
				<c-rt:when test="${ so.orderSt=='00' }">
				${so.orderSt }(待审核)
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='10' }">
				申请中
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='20' }">
				换货已发货
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='30' }">
				换货品验收失败
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='40' }">
				换货转退货
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='50' }">
				换货逾期
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='60' }">
				换货商品退回
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='70' }">
				换货失败
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='80' }">
				换货取消
				</c-rt:when>
				<c-rt:when test="${ so.orderSt=='90' }">
				换货完成
				</c-rt:when>
				
			</c-rt:choose>
		</c-rt:when>
		<c-rt:otherwise>
		${so.orderSt }
		</c-rt:otherwise>
		</c-rt:choose>
		</td>
	</tr>
	<tr>
		<td>
		收货人姓名：${so.receiverName }
		</td>
		<td>
		手机号码：${so.receiverMobile }
		</td>
		<td>
		物流单号：<a href="${logisticUrl }" target="_blank">${logisticNum }</a>
		</td>
	</tr>
	<tr>
		<td>原因：${so.reason }</td>
		<td>订单编号：${so.orderId }
		</td>
		<td>付款方式：${pu:menuOption('Order.PaymentTp', so.paymentTp).name }
		</td>
	</tr>
	<tr>
		<td>订单类型：${so.orderType==1?'一般':'SCM' }</td>
		<td>
			新服务单号：${so.newServiceId}
		</td>
		<td>
			原服务单号：${so.oldServiceId}
		</td>
	</tr>
	<c-rt:if test="${so.orderType=='0'}">
		<tr>
			<td colspan="3">
				${pu:reqSet('supplierApply', pu:get('com.yaodian100.ec.supplierapply.entity.SupplierApply', so.scmSupplierId)) }
				转单供应商：${supplierApply.companyName }
			</td>
		</tr>
	</c-rt:if>
	<tr>
		<td colspan="3">原因描述：${so.description }</td>
		
	</tr>
	<tr>
		<td colspan="3">退回至: 地址：${so.returnAddr} &nbsp;&nbsp;
		邮编：${so.returnZip}&nbsp;&nbsp;
		联络人：${so.returnContact} 电话：${so.returnPhone}</td>
		
	</tr>
	
	<c-rt:if test="${so.returnSt=='30'}">
	<tr>
		<td colspan="3">
		退款日期：<fmt-rt:formatDate value="${so.refundDate }" pattern="yyyy-MM-dd"/> 已退金额：${so.realCash+so.realInstallmentFee } 已退积分：<c-rt:if test = "${not empty order.orderBonusCampaign}">${so.realBonus*order.orderBonusCampaign.offsetRate}</c-rt:if><c-rt:if test = "${empty order.orderBonusCampaign}">0</c-rt:if> 已退我的帐户：${so.realMyWallet } 已退我的礼品卡：${so.realGiftcardBalance }
		</td>
		
	</tr>
	</c-rt:if>
</table>
<iframe src="<%=ServerValue.getBackHostname()%>/erp/crm/sso/crmViewStatus.do?targetSsoId=${so.serviceId}" width="100%" height="220px" frameborder="0"></iframe> 
<table class="tb-1 tableAlignLeft">
<thead>
<tr>
	<th>商品名称</th><th>类型</th><th>数量</th><th>价格</th><th>属性</th><th></th>
</tr>
</thead>
<tbody>
<c-rt:forEach items="${sops}" var="sop">
<tr>
	<td>
	
		<ul>
			<c-rt:forEach items="${sop.serviceOrderDetail }" var="sod">

				<li style="line-height:20px">
					--${sod.prodName }
				</li>

			</c-rt:forEach>
		</ul>
	</td>
	<td style="text-align:center">
		
		<ul>
			<c-rt:forEach items="${sop.serviceOrderDetail}" var="sod">

				<li style="line-height:20px">
					${pu:menuOption('Product.Type', sod.detailTp).name }
				</li>

			</c-rt:forEach>
		</ul>
	</td>
	<td style="text-align:center">

		<ul>
			<c-rt:forEach items="${sop.serviceOrderDetail }" var="sod">

				<li style="line-height:20px">
					${sod.qty }
				</li>

			</c-rt:forEach>
		</ul>
	</td>
	<td style="text-align:center">

		<ul>
			<c-rt:forEach items="${sop.serviceOrderDetail }" var="sod">

				<li style="line-height:20px">
					${pu:currency(sod.unitPrice) }
				</li>

			</c-rt:forEach>
		</ul>
	</td>
	<td  style="text-align:center">
		
		<ul>
		<c-rt:if test="${so.srcType=='2'}">
			<c-rt:forEach items="${sop.serviceOrderDetail }" var="sod">

			<li>
				${sod.orgProdSpecName }-->${sod.prodSpecName }
			</li>

			</c-rt:forEach>
		</c-rt:if>
		<c-rt:if test="${so.srcType!='2'}">
			<c-rt:forEach items="${sop.serviceOrderDetail }" var="sod">

			<li style="line-height:20px">
				${sod.orgProdSpecName }
			</li>

			</c-rt:forEach>
		</c-rt:if>
		</ul>
	</td>
	<td style="text-align:center">
		<ul>
			<c-rt:forEach items="${sop.serviceOrderDetail }" var="sod">
				<li>
				
					<s:set name="orderDetailId" >
						${sod.orderDetailId}
					</s:set>
					<s:set name="orderProdId" >
						${sop.orderProdId}
					</s:set>
					
					<s:if test="%{serviceOrderService.isOrderDetailReturnableChangable(#orderDetailId)}">
						<yaodian100:checkPermission permissions="ROLE_ORD">
							<s:form method="post">
								<s:submit value="申请换货" action="serviceOrder" method="toChangeProduct" ></s:submit>
								<s:submit value="申请退货" action="serviceOrder" method="toReturnProduct" ></s:submit>
								<s:hidden name="orderProdId" value="%{#orderProdId}"></s:hidden>
								<s:hidden name="orderDetailId" value="%{#orderDetailId}"></s:hidden>
								<s:hidden name="oldServiceId" value="%{serviceId}" />
							</s:form>
						</yaodian100:checkPermission>
					</s:if>
					<s:else>
						&nbsp;
					</s:else>
				</li>
			</c-rt:forEach>
		</ul>
		
	</td>
</tr>
</c-rt:forEach>
</tbody>
</table>
<c-rt:if test="${so.orderSt=='00'}">
	<c-rt:if test="${!empty param.fromWorkOrder}">
		<c-rt:set var="tagId" value="main"/>
	</c-rt:if>
	<c-rt:if test="${empty param.fromWorkOrder}">
		<c-rt:set var="tagId" value="dialog"/>
	</c-rt:if>
	<input type="button" onclick="location.href='/ecadmin/serviceOrder/confirmReturnProductOnDetail.do?serviceId=${so.serviceId }'" value="审核成功"/>
	<input type="button" onclick="location.href='/ecadmin/serviceOrder/cancelReturnProductOnDetail.do?serviceId=${so.serviceId }'" value="审核失败"/>
	<%--
	<c-rt:if test="${!empty param.from && param.from=='returnAll'}">
				<input type="button" onclick="location.href='/ecadmin/serviceOrder/confirmReturnProductOnDetail.do?serviceId=${so.serviceId }'" value="审核成功"/>
				<input type="button" onclick="location.href='/ecadmin/serviceOrder/cancelReturnProductOnDetail.do?serviceId=${so.serviceId }'" value="审核失败"/>
	</c-rt:if>
	<c-rt:if test="${empty param.from || param.from!='returnAll'}">
				<input type="button" onclick="doAR('<c-rt:url value="/serviceOrder/confirmReturnProductOnDetail.do?serviceId=${so.serviceId }"/>', '${tagId }')" value="审核成功"/>
				<input type="button" onclick="doAR('<c-rt:url value="/serviceOrder/cancelReturnProductOnDetail.do?serviceId=${so.serviceId }"/>', '${tagId }')" value="审核失败"/>
	</c-rt:if>
	 --%>
				<input type="button" onclick="location.href='/ecadmin/serviceOrder/toReturnToChange.do?serviceId=${so.serviceId }'" value="退货转换货"/>
				</c-rt:if>
<c-rt:choose>
<c-rt:when test="${!empty param.serviceId && empty param.fromWorkOrder && (!empty param.from && param.from=='list')}">
<input type="button" value="返回查询页" onclick="location.href='<c-rt:url value="/serviceOrder/page.do?iamlazy=${param.from }"/>'"/>
</c-rt:when>

<c-rt:when test="${param.from=='orderView'}">
<input type="button" value="返回订单页" onclick="history.back()"/>
</c-rt:when>
<c-rt:when test="${!empty param.orderProdId}">
<input type="button" value="关闭" onclick="closeDialog()"/>
</c-rt:when>
</c-rt:choose>
<c-rt:if test="${so.srcType=='1' || so.srcType=='2'}">
	<input type="button" onclick="location.href='<c-rt:url value="/serviceOrder/trackcase/add.do?orderIdParam=${so.orderId}&serviceIdParam=${so.serviceId}&caseTypeParam=${so.srcType}"/>'" value="追踪此案件"/>
</c-rt:if >
